public class Array {
    native float[] arrayFromC(float[] input, int size); /* (1) */
    static {
        System.loadLibrary("array"); /* (2) */
    }
    public static void main(String args[]) {
        Array a = new Array();
        int size = Integer.parseInt(args[1]);
        float[] data = new float[size];
        for (int i=0; i<data.length; i++) {
        	data[i] = (float)Math.random();
        }
        double result = 0;
        int iteration = Integer.parseInt(args[0]);
	float[]answer = new float[size];
	//skip the first call to JNI (it takes longer)
	if(Integer.parseInt(args[2])==1)
		answer = a.arrayFromC(data, size);
        for (int i = 0; i<iteration; i++){
        	long starttime = System.nanoTime();
	        answer = a.arrayFromC(data, size);
	        long endtime =  System.nanoTime();
	        result += endtime - starttime;
        }
	result = result*0.000001;
        /*System.out.println ("Average time of passing an array of floats of size "
        					+ args[0]
        					+ ", reading it into c environment and passing it back to java over " + args[1] + " iterations"
        					+ " is "
        					+ Double.toString(result / Integer.parseInt(args[1])) +" milliseconds");*/
	System.out.format(args[1]+" %f %f\n", result/iteration, (result/iteration)/size); //array length, time per iteration, time per element
           
    }
}
